import { merge } from 'webpack-merge';
import { CleanWebpackPlugin } from 'clean-webpack-plugin';
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';

import { getCommonWebpackConfig } from './webpack.common';
import { UnionWebpackConfigWithDevelopmentServer } from '../types';
import { WebpackConfig } from '../constants';

function getDevelopmentWebpackConfig(): UnionWebpackConfigWithDevelopmentServer {
    const commonConfig = getCommonWebpackConfig(true);

    return merge(commonConfig, {
        devtool: 'eval-cheap-module-source-map',
        mode: 'development',
        stats: {
            errorDetails: true,
        },
        // output: {
        //     path: path.resolve(PROJECT_PATH, `./dist/development/static`),
        //     filename: `scripts/[name].js`,
        // },
        cache: {
            type: 'filesystem',
            //name: 'development-cache',
            //cacheLocation: path.resolve('../../../dist/cache'),
            // buildDependencies: {
            //     config: [__filename],
            // },
        },
        plugins: [
            new CleanWebpackPlugin(),

            // new HardSourceWebpackPlugin(), //only use in dev environment
            // new HardSourceWebpackPlugin.ExcludeModulePlugin([
            //     {
            //         test: /mini-css-extract-plugin[\\/]dist[\\/]loader/,
            //     },
            // ]),
            // new BundleAnalyzerPlugin({
            //     // analyzerMode: "", // 开一个本地服务查看报告
            //     // analyzerHost: 'localhost', // host 设置
            //     // analyzerPort: 9628, // 端口号设置
            //     analyzerMode: 'static', // static mode
            //     reportFilename: './dist/analyzer/report.html',
            // }),
        ],
    });
}

export default getDevelopmentWebpackConfig();
